<!--
 * @Author: wang
 * @Date: 2020-09-22 18:05:20
 * @LastEditTime: 2020-08-13 09:16:04
 * @LastEditors: wang
 * @Description: 应急调度 范围搜索
 * @FilePath: \c-u-f\src\App.vue
-->
<template>
  <div :class="themeClass" style="height:100%;">
    <div class="tab_box">
      <div class="tab_head">
        <div v-for="(tabitem, index) in tab" :key="index">
          <div :class="['tab_item ', tabindex == index ? 'tab_active' : '']" @click="Tabswitch(index)">{{ tabitem }}</div>
        </div>
      </div>
      <div style="width:100%;max-height:811px;" v-if="tabindex == 0">
        <div class="container" style="width:99%;">
          <table>
            <thead>
              <tr class="tabOne" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
                <th style="width:20px;margin-right:5px;"></th>
                <th class="widthOne">名称</th>
                <th class="widthOne">级别</th>
                <th class="widthOne">人数</th>
                <th class="widthTwo">负责人</th>
                <th class="widthThre">联系电话</th>
              </tr>
            </thead>
            <tbody style="box-sizing:border-box;padding:10px 0;opacity: 0.5;" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
              <template v-if="!isShowhasdj">
                <tr v-for="(item, index) in Rescueteamlist" :key="index" :class="[item.isSelected == 1 ? 'bg' : '']">
                    <td class="checkbox" style="width:20px;">
                    <input type="checkbox" :checked="item.isSelected == 1 ? true : false" />
                    <label class="chckbx" @click="check(item, $event)"></label>
                    </td>
                    <td class="widthOne" :title="item.teamName">{{ item.teamName }}</td>
                    <td class="widthOne" :title="item.level">{{ item.level }}</td>
                    <td class="widthOne" :title="item.number">{{ item.number }}</td>
                    <td class="widthTwo" :title="item.responsiblePeople">{{ item.responsiblePeople }}</td>
                    <td class="widthThre" :title="item.phone">{{ item.phone }}</td>
                </tr>
              </template>
              <template v-else>
                  <div class="list_item" v-for="(item, index) in Rescueteamlist" :key="index">
                      已调度{{item.teamName}}
                  </div>
              </template>
            </tbody>
          </table>
        </div>
      </div>
      <div style="width:100%;max-height:811px;" v-if="tabindex == 1">
        <div class="container" style="width:99%;">
          <table>
            <thead>
              <tr class="tabOne" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
                <th style="width:20px;margin-right:5px;"></th>
                <th class="widthOne">名称</th>
                <th class="widthOne">地点</th>
                <th class="widthTwo">隶属区域</th>
                <th class="widthTwo">联系人</th>
                <th class="widthThre">联系电话</th>
              </tr>
            </thead>
            <tbody style="box-sizing:border-box;padding:10px 0;opacity: 0.5;" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
                <template v-if="!isShowhasdj">
                    <tr v-for="(item, index) in material" :key="index" :class="[item.isSelected == 1 ? 'bg' : '']">
                        <td class="checkbox" style="width:20px;">
                        <input type="checkbox" :checked="item.isSelected == 1 ? true : false" />
                        <label class="chckbx" @click="check(item, $event)"></label>
                        </td>
                        <td class="widthOne" :title="item.suppliesName">{{ item.suppliesName }}</td>
                        <td class="widthOne" :title="item.address">{{ item.address }}</td>
                        <td class="widthTwo" :title="item.regionName">{{ item.regionName }}</td>
                        <td class="widthOne" :title="item.siteName">{{ item.siteName }}</td>
                        <td class="widthTwo" :title="item.phone">{{ item.phone }}</td>
                    </tr>
                </template>
                <template v-else>
                  <div class="list_item" v-for="(item, index) in material" :key="index">
                      已调度{{item.suppliesName}}
                  </div>
              </template>
            </tbody>
          </table>
        </div>
      </div>
      <div style="width:100%;max-height:811px;" v-if="tabindex == 2">
        <div class="container" style="width:99%;">
          <table>
            <thead>
              <tr class="tabOne" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
                <th style="width:20px;margin-right:5px;"></th>
                <th class="widthOne">名称</th>
                <th class="widthOne">地址</th>
                <th class="widthTwo">区域</th>
                <th class="widthTwo">面积(m²)</th>
                <th class="widthThre">人数</th>
              </tr>
            </thead>
            <tbody style="box-sizing:border-box;padding:10px 0;opacity: 0.5;" :class="[theme == 'dark' ? 'bk1' : 'bk2']">
                <template v-if="!isShowhasdj">
                    <tr v-for="(item, index) in Avoidingdisaster" :key="index" :class="[item.isSelected == 1 ? 'bg' : '']">
                        <td class="checkbox" style="width:20px;">
                        <input type="checkbox" :checked="item.isSelected == 1 ? true : false" />
                        <label class="chckbx" @click="check(item, $event)"></label>
                        </td>
                        <td class="widthOne" :title="item.siteName">{{ item.siteName }}</td>
                        <td class="widthOne" :title="item.address">{{ item.address }}</td>
                        <td class="widthTwo" :title="item.regionName">{{ item.regionName }}</td>
                        <td class="widthTwo" :title="item.area">{{ item.area }}</td>
                        <td class="widthThre" :title="item.capacity">{{ item.capacity || 0 }}</td>
                    </tr>
                </template>
                <template v-else>
                  <div class="list_item" v-for="(item, index) in Avoidingdisaster" :key="index">
                      已调度{{item.siteName}}
                  </div>
              </template>
            </tbody>
          </table>
        </div>
      </div>
      <div class="btn_box">
        <div class="btn" v-if="!isShowhasdj" @click="getRoute">确定</div>
        <div class="btn" v-else @click="backList">返回</div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { getPlanPaths } from '@/utils/map/routePlan'
import { scheduleScopeAffected } from '@/api/index.js'
export default {
  props: {
    Rescueteamlist: {
      type: Array
    },
    material: {
      type: Array
    },
    Avoidingdisaster: {
      type: Array
    },
    popObj: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 是否是只显示勾选的
    isShowhasdj: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      tab: ['救援队', '物资点', '避灾点'],
      tabindex: 0
    }
  },
  computed: {
    ...mapState(['theme']),
    themeClass () {
      return `theme-${this.theme}`
    }
  },
  methods: {
    Tabswitch (index) {
      this.tabindex = index
    },
    check (obj) {
      obj.isSelected = obj.isSelected === 0 ? 1 : 0
    },
    // 点击返回
    backList () {
      // 显示全部数据
      this.$parent.isShowhasdj = false
      // 调取获取接口数据
      this.$parent.getscopeScheduleSearch()
    },
    getscopeScheduleSearch () {},
    // 获取路线
    getRoute () {
      let startPoint = [this.popObj.x, this.popObj.y]
      let jydlist = this.Rescueteamlist.filter(item => item.isSelected === 1)
      let wzdlist = this.material.filter(item => item.isSelected === 1)
      let bzdlist = this.Avoidingdisaster.filter(item => item.isSelected === 1)
      let jydPointlist = jydlist.map(item => {
        return {
          id: item.id,
          x: item.x,
          y: item.y
        }
      })
      let wzdPointlist = wzdlist.map(item => {
        return {
          id: item.id,
          x: item.x,
          y: item.y
        }
      })
      let bzdPointlist = bzdlist.map(item => {
        return {
          id: item.id,
          x: item.x,
          y: item.y
        }
      })
      let jydRouterlist = []
      let promiseAll = []
      if (jydPointlist) {
        let jydCount = 0
        for (let i = 0; i < jydPointlist.length; i++) {
          if (jydCount === i) {
            jydCount++
            promiseAll.push(
              getPlanPaths({
                start: startPoint,
                end: [jydPointlist[i].x, jydPointlist[i].y]
              }).then(res => {
                jydRouterlist.push(JSON.stringify(res.route.paths[0]))
              })
            )
          }
        }
      }
      let wzdRouterlist = []
      if (wzdPointlist.length) {
        wzdPointlist.forEach(item => {
          promiseAll.push(
            getPlanPaths({
              start: startPoint,
              end: [item.x, item.y]
            }).then(res => {
              wzdRouterlist.push(JSON.stringify(res.route.paths[0]))
            })
          )
        })
      }

      let bzdRouterlist = []
      if (bzdPointlist.length) {
        bzdPointlist.forEach(item => {
          promiseAll.push(
            getPlanPaths({
              start: startPoint,
              end: [item.x, item.y]
            }).then(res => {
              bzdRouterlist.push(JSON.stringify(res.route.paths[0]))
            })
          )
        })
      }
      Promise.all(promiseAll).then(res => {
        scheduleScopeAffected({
          affectedId: this.popObj.id,
          rescueTeamIds: jydPointlist.map(item => item.id),
          settlementIds: bzdPointlist.map(item => item.id),
          suppliesIds: wzdPointlist.map(item => item.id),
          rescueTeamPolyline: jydRouterlist,
          settlementPolyline: bzdRouterlist,
          suppliesPolyline: wzdRouterlist
        }).then(res => {
          if (res.code === 200) {
            console.log(res)
            // this.$Message.success('路线规划添加成功')
            this.$parent.isShowhasdj = true // 只显示被调用的点
            // 修改显示
            this.$parent.confirmBtn(jydlist, wzdlist, bzdlist)
          } else this.$Message.error(res.message)
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/index.scss';
.tab_box {
  width: 347px;
  height: 100%;
  background-size: 347px 100%;
  margin-left: auto;
  margin-top: 17px;
  z-index: 9999;
  margin-right:-1px;
  box-sizing:border-box;
  padding-bottom:30px;
  @include themify($themes) {
    background: themed('dispatch_list_bj');
  }
}
.tab_head {
  width: 100%;
  display: flex;
  box-sizing: border-box;
  padding: 10px 43px;
}
.tab_item {
  width: 80px;
  height: 30px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 30px;
  text-align: center;
  opacity: 0.7;
  cursor: pointer;
  margin-right: 10px;
  @include themify($themes) {
    background: themed('tab_item_bj');
    color: themed('search_font1');
  }
}
.bk1 {
  border-bottom: 1px solid #ffffff;
}
.bk2 {
  border-bottom: 1px solid #425a64;
}
.tab_active {
  line-height: 28px;
  @include themify($themes) {
    background: themed('  tab_active_bj');
    color: themed('active_color');
  }
}
.theme-light .tab_active {
  border: 1px solid #027aff;
}
.theme-dark .tab_active {
  border: 1px solid #72e6ff;
}
.tab_box .container table tbody {
  width: 100%;
  height: calc(100vh - 230px);
  overflow-y: auto;
}
// 滚动条整体部分
.tab_box .container table tbody::-webkit-scrollbar {
  width: 4px;
  opacity: 1;
}
//滚动条里面的滑块
.tab_box .container table tbody::-webkit-scrollbar-thumb {
  height: 20px;
  @include themify($themes) {
    background: themed('t-gdt-hk-bj');
  }
}
//滚动条的轨道
.tab_box .container table tbody::-webkit-scrollbar-track {
  @include themify($themes) {
    background: themed('t-gdt-gd-bj');
  }
}
.bg td {
  @include themify($themes) {
    background: themed('bg');
  }
}

.container table {
  font-size: 14px;
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
  @include themify($themes) {
    color: themed('table_color_h');
  }
}

.conatiner table thead,
tbody,
tr,
th,
td {
  display: inline-block;
}

.container table thead {
  width: 100%;
  height: 40px;
  line-height: 40px;
  @include themify($themes) {
    color: themed('table_color_h');
  }
}

.container table thead tr {
  width: 100%;
  box-sizing: border-box;
}
.container table tbody tr {
  width: 100%;
  line-height: 25px;
  box-sizing: border-box;
  padding: 0;
  margin-bottom: 6px;
}

.container table tbody tr:nth-last-of-type(1) {
  border-bottom: none;
}

.container table tbody tr td {
  text-align: center;
}
.container table tbody .checkbox {
  width: 20px;
  border: none;
  background: none;
  margin-right: 5px;
  text-align: right;
  flex: none;
}
.checkbox .chckbx {
  height: 14px;
  width: 14px;
  border-radius: 2px;
  display: inline-block;
  vertical-align: middle;
}
.theme-light .checkbox .chckbx {
  border: 1px solid #027aff;
}
.theme-dark .checkbox .chckbx {
  border: 1px solid #71e6ff;
}
.checkbox input[type='checkbox']:checked + .chckbx {
  background-size: contain;
  border: none;
  @include themify($themes) {
    background-image: themed('checked2');
  }
}

.checkbox input[type='checkbox'] {
  vertical-align: middle;
  width: 15px;
  height: 15px;
  display: none;
}
.btn_box {
  width: 100%;
  margin-top: 30px;
  text-align: center;
}
.btn {
  width: 80px;
  height: 30px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 24px;
  opacity: 0.8;
  margin: 0 auto;
  cursor: pointer;
  @include themify($themes) {
    background: themed('btn');
    color: themed('btn_color');
  }
}
.theme-light .btn {
  border: 1px solid #027aff;
}
.theme-dark .btn {
  border: 1px solid #72e6ff;
}
.widthOne {
  width: 50px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.widthTwo {
  width: 60px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.widthThre {
  width: 80px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.tabOne {
  opacity: 0.5;
}
.list_item {
  margin-top: 10px;
  font-size: 14px;
  padding-left: .625rem /* 10/16 */;
  // color: #ffffff;
  opacity: 0.5;
  @include themify($themes) {
    color: themed('list_item');
  }
}
</style>
